package domain.grammar;

import java.util.Iterator;
import java.util.Set;

import domain.regularExpression.RegularExpressionElement;

public class ExtendedProductionSet {
	private Set<ExtendedProduction> _productions;
	
	
	
	public ExtendedProductionSet(Set<ExtendedProduction> _productions) {
		super();
		this._productions = _productions;
	}
	
	

	public Set<ExtendedProduction> get_productions() {
		return _productions;
	}

	
	
	public ExtendedProduction getProductionByLeftSide(ExtendedNonTerminalSymbol ent){
		Iterator<ExtendedProduction> itProd = _productions.iterator();
		while(itProd.hasNext()){
			ExtendedProduction aProd = (ExtendedProduction) itProd.next();
			if(aProd.get_leftSide().equals(ent)){
				return aProd;
			}
		}
		throw new RuntimeException("No production were found with this left side: "+ent);
	}
	
	
	public String toString(){
		return showSet(this._productions);
	}
	
	private String showSet(Set<?> aSet){
		String result = "{";
		boolean isFirstIt = true;
		Iterator<?> itSet = aSet.iterator();
		while(itSet.hasNext()){
			Object anElem = itSet.next();
			if(!isFirstIt){
				result = result +", \n";
			}
			result = result + anElem.toString();
			isFirstIt = false;
		}
		result = result + "}";
		return result;
	}
	
	
}
